package com.kaisademo.zhxy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kaisademo.zhxy.pojo.Clazz;
import com.kaisademo.zhxy.service.ClazzService;
import com.kaisademo.zhxy.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "班级控制器")
@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    @ApiOperation("删除一个或者多个班级信息")
    @DeleteMapping("/deleteClazz")
    public Result deleteClazz(
            @ApiParam("多个班级id的JSON")
            @RequestBody List<Integer> ids){
        clazzService.removeByIds(ids);
        return Result.ok();
    }
    @ApiOperation("新增或修改班级")
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(
            @ApiParam("JSON转换后端Clazz数据模型")
            @RequestBody Clazz clazz){
        clazzService.saveOrUpdate(clazz);
        return Result.ok();
    }

    @ApiOperation("查询班级信息,分页带条件")
    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzsByOpr(
            @ApiParam("页码数")
            @PathVariable(value = "pageNo") Integer pageNo,
            @ApiParam("页大小")
            @PathVariable(value = "pageSize") Integer pageSize,
            @ApiParam("查询条件")
            Clazz clazz
    ){
        Page<Clazz> clazzPage = new Page<>(pageNo,pageSize);
        IPage<Clazz> clazzIPage = clazzService.getClazzsByOpr(clazzPage,clazz);
        return Result.ok(clazzIPage);
    }
}
